home *** CD-ROM | disk | FTP | other *** search
- Path: usenet.ee.pdx.edu!fastrac.llnl.gov!lll-winken.llnl.gov!uwm.edu!ux1.cso.uiuc.edu!howland.reston.ans.net!xlink.net!math.fu-berlin.de!news.th-darmstadt.de!hotb.RoBIN.de!batman.RoBIN.de!mania.RoBIN.de!mania!lkv
- From: lkv@mania.RoBIN.de (Lutz Vieweg)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: Request for C++ Task Class for Multitasking on Amiga
- Message-ID: <VS72t*X43@mania.RoBIN.de>
- Date: Tue, 08 Jun 1993 15:22:17 GMT
- References: <2C0E1CDB.5AE9@deneva.sdd.trw.com>
- Organization: The Funny Farm
- X-Newsreader: Arn V1.00 alpha rel3
- Lines: 180
-
- In article <2C0E1CDB.5AE9@deneva.sdd.trw.com>, Scott Karlin writes:
-
- > I'm looking for a C++ task class for the Amiga. Has anyone
- > implemented such a thing? (I'm using Comeau C++ with SAS/C.)
-
-
- I've implemented a Process class for GNU C++, maybe it can give
- you some ideas.
-
- Needs DOSLib (a class wich simply provides opening and closing of the
- dos.library) and some simple external error-handling routines.
-
- ------------- AmiProcess.h ---------------
-
- #ifndef AmiProcess_h
- #define AmiProcess_h
-
- extern "C" {
- #include <exec/types.h>
- #include <exec/tasks.h>
- #include <inline/exec.h>
-
- }
-
- #include "DOSLib.h"
-
- class AmiProcess {
-
- DOSLib dl;
-
- volatile char run_flag;
- volatile char start_flag;
- long atn_signal;
- long atn_signal_num;
- struct Task * pro_task;
- void (*func)(void);
- static unsigned long thisbuf;
-
- void ProcUpStart(void);
-
- public:
- char fail;
-
- AmiProcess(void (*funktion)(), unsigned long int StackSize = 4096,
- char * ProcName = "New Process");
-
-
- ~AmiProcess();
- void leave();
-
- void start(void);
-
- void signal(long sigs);
-
- inline volatile char running(void) {return run_flag;};
- inline long get_atn_bit(void) {return atn_signal;};
- inline int test_atn(void) {return (SetSignal(0L,0L) & atn_signal);};
- };
-
- #endif AmiProcess_h
-
- ------------------------- AmiProcess.cc ------------------------
-
- #include "AmiProcess.h"
-
- #include "set_error.h"
-
- extern "C" {
- #include <dos/dostags.h>
- }
-
- unsigned long AmiProcess::thisbuf = 0;
-
- extern "C" void AmiProcessRealUpstart(void);
-
- void AmiProcess::ProcUpStart(void) {
-
- asm("_AmiProcessRealUpstart:
- movel %1,%0" : "=r" (this) : "m" (thisbuf));
-
- if ((atn_signal_num = AllocSignal(-1L))==-1) {
- set_error("AmiProcess::ProcUpStart ","cannot allocate atn_signal");
- }
-
- atn_signal = 1 << atn_signal_num;
-
- pro_task = FindTask(0L);
-
- run_flag = 1;
-
- Wait(atn_signal);
-
- if (start_flag) (*func)();
-
- FreeSignal(atn_signal_num);
-
- run_flag=0;
-
- asm("rts");
- }
-
- AmiProcess::AmiProcess(void (*funktion)(), unsigned long int StackSize,
- char * ProcName) : dl(), fail(0) {
-
- asm("movel %1,%0" : "=m" (thisbuf) : "r" (this));
-
- run_flag = start_flag = 0;
-
- func = funktion;
-
- if (!(CreateNewProcTags(NP_Entry, (ULONG)&AmiProcessRealUpstart,
- NP_Input, Input(),
- NP_Output, Output(),
- NP_StackSize, StackSize,
- NP_Name, (ULONG)ProcName,
- NP_CloseInput, (ULONG) 0,
- NP_CloseOutput, (ULONG) 0,
- TAG_END, 0L))) {
- set_error("AmiProcess::AmiProcess ","CreateNewProc() failed");
- fail = -1;
- }
- else {
- for (int i=0; i<30; i++) {
- if (run_flag) break;
- Delay(5);
- }
- if (!(run_flag)) {
- set_error("AmiProcess::AmiProcess ","child does not start up");
- fail = -1;
- }
- }
-
-
- }
-
-
- AmiProcess::~AmiProcess () {
-
- leave();
-
- }
-
- void AmiProcess::leave(void) {
-
- int i;
-
- if (run_flag) {
-
- start_flag = 0;
- Signal(pro_task,atn_signal);
-
- for (i=0; i<30; i++) {
- if (!(run_flag)) break;
- Delay(5);
- }
-
- if (run_flag) set_error("AmiProcess::leave ","child don't wanna exit");
- }
- }
-
- void AmiProcess::start() {
-
- start_flag = 1;
- Signal(pro_task,atn_signal);
-
- }
-
- void AmiProcess::signal(long sigs) {
-
- if (run_flag) {
- Signal(pro_task,sigs);
- }
- }
-
- -----------------------------------------------------------------
-
- Flames about code-style, documentation and so on >NIL:
-
- cu, Lutz Vieweg
-
-
-